package com.study.eurekaclienthystrix;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@EnableHystrix // 开启熔断器支持
@EnableEurekaClient // eureka 客户端标识
@EnableFeignClients // 开启 feign 支持
@SpringBootApplication
public class RurekaClientHystrixApplication {

    public static void main(String[] args) {
        SpringApplication.run(RurekaClientHystrixApplication.class, args);
    }

    /**
     * ribbon 负载均衡
     */
    @Bean
    @LoadBalanced
    RestTemplate restTemplate() {
        return new RestTemplate();
    }

    /**
     * 负载策略
     */
    @Bean
    public IRule myRule() {
        return new RandomRule();
        //return new RoundRobinRule();
        //return new RetryRule();
    }

}
